package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.MenuTypeDAO;
import com.swlz.entity.MenuType;
import com.swlz.exception.CodeException;
import com.swlz.service.MenuTypeService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 系统菜单类型
 * ClassName : com.swlz.service.impl.MenuTypeServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-06-25 13:28:41
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class MenuTypeServiceImpl implements MenuTypeService {
	
	private MenuTypeDAO menuTypeDAO = new MenuTypeDAO();

	@Override
	public int add(MenuType menuType) throws CodeException {
		try {
			return menuTypeDAO.insertSelective(menuType);
		} catch (SQLException e) {
			throw new CodeException(500, "添加系统菜单类型错误",e);
		}
	}

	@Override
	public int update(MenuType menuType) throws CodeException {
		try {
			return menuTypeDAO.updateSelective(menuType);
		} catch (SQLException e) {
			throw new CodeException(501, "修改系统菜单类型错误",e);
		}
	}

	@Override
	public int delete(Long menuTypeId) throws CodeException {
		try {
			return menuTypeDAO.deleteById(menuTypeId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除系统菜单类型错误",e);
		}
	}

	@Override
	public MenuType get(Long menuTypeId) throws CodeException {
		try {
			return menuTypeDAO.selectById(menuTypeId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取系统菜单类型失败",e);
		}
	}

	@Override
	public PageVO<MenuType> page(MenuType menuType, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = menuTypeDAO.countByModel(menuType);
			PageVO<MenuType> page = new PageVO<>(total, current, rowMax);
			return page.setList(menuTypeDAO.selectByModel(menuType, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取系统菜单类型分页数据失败",e);
		}
	}


}
